package com.dc.wifi.main.adapter


import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import com.chad.library.adapter4.BaseMultiItemAdapter
import com.dc.wifi.R
import com.dc.wifi.databinding.ItemDeviceType1Binding
import com.dc.wifi.databinding.ItemDeviceType2Binding
import com.dc.wifi.main.Commons.ConstantDevice
import com.dc.wifi.main.adapter.entity.DeviceEntity
import com.dc.wifi.main.adapter.viewholder.DeviceBaseItemViewHolder
import com.dc.wifi.main.adapter.viewholder.DeviceType2ViewHolder

class AdapterDevice(data: List<DeviceEntity>) : BaseMultiItemAdapter<DeviceEntity>(data) {
init {

    addItemType(ConstantDevice().ITEM_TYPE,  object : OnMultiItemAdapterListener<DeviceEntity, DeviceBaseItemViewHolder> {
        override fun onCreate(context: Context, parent: ViewGroup, viewType: Int): DeviceBaseItemViewHolder {
            val viewBinding =
                ItemDeviceType1Binding.inflate(LayoutInflater.from(context), parent, false)
            return DeviceBaseItemViewHolder(viewBinding)
        }
        override fun onBind(holder: DeviceBaseItemViewHolder, position: Int, item: DeviceEntity?) {
            if (item == null) return
//            holder.viewBinding.textView.text = item.name
        }
    }).addItemType(ConstantDevice().SECTION_TYPE,  object : OnMultiItemAdapterListener<DeviceEntity, DeviceType2ViewHolder> {
        override fun onCreate(context: Context, parent: ViewGroup, viewType: Int): DeviceType2ViewHolder {
            val viewBinding =
                ItemDeviceType2Binding.inflate(LayoutInflater.from(context), parent, false)
            return DeviceType2ViewHolder(viewBinding)
        }
        override fun onBind(holder: DeviceType2ViewHolder, position: Int, item: DeviceEntity?) {
            if (item == null) return
            holder.viewBinding.textView.text = item.name
        }
    }).onItemViewType { position, list ->
        list[position].type
    }
}




}